#include "Fader.h"


/** time tick to update volume */
#define DEFAULT_VOLUME_UPDATE_MS    100


Fader::Fader(QObject *parent) :
   QObject(parent)
{
   m_isFading = false;
   m_volume = 0.0;

   connect( &m_volumeUpdateTimer, SIGNAL(timeout()),
            this, SLOT(onVolumeUpdateTick()) );
}

/**
 * start value of transition
 * @param startVolume - range 0..100
 */
void Fader::startFrom(int startVolume)
{
   m_volume = (qreal)startVolume;
   m_volumeUpdateTimer.start( DEFAULT_VOLUME_UPDATE_MS );
   m_isFading = true;
}

void Fader::stop()
{
   m_volumeUpdateTimer.stop();
   m_isFading = false;
}


void Fader::toggleFrom(int startVolume)
{
   m_isFading ? stop() : startFrom(startVolume);
}
